define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/taskposition/index',
                    add_url: 'jdy/taskposition/add',
                    edit_url: 'jdy/taskposition/edit',
                    del_url: 'jdy/taskposition/del',
                    multi_url: 'jdy/taskposition/multi',
                    table: 'jdy_taskposition',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'task_id', title: __('Task_id')},
                        {field: 'lng', title: __('Lng')},
                        {field: 'lat', title: __('Lat')},
                        {field: 'task_status', title: __('Task_status'), formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'luruman', title: __('Luruman')},
                        {field: 'task.id', title: __('Task.id')},
                        {field: 'task.anchang_id', title: __('Task.anchang_id')},
                        {field: 'task.remind_type', title: __('Task.remind_type')},
                        {field: 'task.remind_date', title: __('Task.remind_date'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'task.replay', title: __('Task.replay')},
                        {field: 'task.quotation_no', title: __('Task.quotation_no')},
                        {field: 'task.work_no', title: __('Task.work_no')},
                        {field: 'task.title', title: __('Task.title')},
                        {field: 'task.task_status', title: __('Task.task_status'), formatter: Table.api.formatter.status},
                        {field: 'task.maintenanceuser_id', title: __('Task.maintenanceuser_id')},
                        {field: 'task.handleuser_id', title: __('Task.handleuser_id')},
                        {field: 'task.notifyuser_ids', title: __('Task.notifyuser_ids')},
                        {field: 'task.share_to_comm', title: __('Task.share_to_comm')},
                        {field: 'task.notify_msg', title: __('Task.notify_msg')},
                        {field: 'task.acdevice_ids', title: __('Task.acdevice_ids')},
                        {field: 'task.baogu', title: __('Task.baogu')},
                        {field: 'task.images', title: __('Task.images'), formatter: Table.api.formatter.images},
                        {field: 'task.price', title: __('Task.price')},
                        {field: 'task.luruman', title: __('Task.luruman')},
                        {field: 'task.create_time', title: __('Task.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'task.update_time', title: __('Task.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});